package com.itsu.mongodb.service.impl;

import com.itsu.interfaces.entity.Album;
import com.itsu.interfaces.service.AlbumService;
import com.itsu.pojo.constants.Constants;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class AlbumServiceImpl implements AlbumService {

    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public void saveAlbum(Album album, Long uid) {
        mongoTemplate.save(album, Constants.ALBUM_DATABASE_NAME + uid);
    }

    @Override
    public List<Album> findAlbums(Long userId) {
        return mongoTemplate.find(new Query(), Album.class, Constants.ALBUM_DATABASE_NAME + userId);
    }
}
